package so.sao.code.service.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import so.sao.code.service.domain.entity.EnterpriseDomain;
import so.sao.code.service.repository.EnterpriseDomainDao;
import so.sao.code.service.service.EnterpriseDomainService;

@Service
public class EnterpriseDomainServiceImpl implements EnterpriseDomainService {

    @Autowired
    private EnterpriseDomainDao enterpriseDomainDao;

    /**
     * 默认的子域名，小企业以及没有配置域名的企业会使用该默认子域名
     */
    @Value("${sao.code.key.default-sub-domain}")
    private String defaultSubDomain;


    @Override
    public List<EnterpriseDomain> findByEseId(Long eseId) {
        List<EnterpriseDomain> list = new ArrayList<>();
        //list.add(enterpriseDomainDao.findByEseId(eseId));
        return list;
    }

    @Override
    public EnterpriseDomain save(EnterpriseDomain enterpriseDomain) {
        return enterpriseDomainDao.save(enterpriseDomain);
    }

    @Override
    public EnterpriseDomain update(EnterpriseDomain enterpriseDomain) {
        return enterpriseDomainDao.save(enterpriseDomain);
    }

    @Override
    public String findSubDomain(Long eseId) {
//      EnterpriseDomain enterpriseDomain = enterpriseDomainDao.findByEseId(eseId);
//		return enterpriseDomain == null ? defaultSubDomain : enterpriseDomain.getSubDomain();
        return defaultSubDomain;
    }
}
